﻿namespace WPForms.Common.Model
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Partial class for the FormSection with implementation of methods.
    /// </summary>
    [Description("A form section can contain any number of fields and sections. Use this to organize related fields.")]
    [System.Runtime.Serialization.DataContract(IsReference = true)]
    public partial class FormSection : FormElement
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FormSection" /> class.
        /// </summary>
        public FormSection()
        {
            this.Children = new System.Collections.ObjectModel.Collection<FormElement>();
            this.Attachments = new System.Collections.ObjectModel.Collection<Attachment>();
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        [Description("The name of the section.")]
        [System.Runtime.Serialization.DataMember]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the children.
        /// </summary>
        [System.Runtime.Serialization.DataMember]
        public virtual System.Collections.ObjectModel.Collection<FormElement> Children { get; set; }

        /// <summary>
        /// Gets or sets the attachments.
        /// </summary>
        [System.Runtime.Serialization.DataMember]
        public virtual System.Collections.ObjectModel.Collection<Attachment> Attachments { get; set; }

        /// <summary>
        /// Validates the element.
        /// Note!! The autogenerated NotImplementedException has to be removed!!
        /// </summary>
        /// <returns>
        /// The result of the validation.
        /// </returns>
        public override IEnumerable<string> Validate()
        {
            var result = new List<string>();
            if (this.Children != null)
            {
                foreach (var child in this.Children)
                {
                    result.AddRange(child.Validate());
                }
            }

            return result;
        }
    }
}
